//
//  BluetoothConnectViewController.m
//  LINNER
//
//  Created by Kendama on 2017/10/11.
//  Copyright © 2017年 weiwang. All rights reserved.
//

#import "BluetoothConnectViewController.h"

@interface BluetoothConnectViewController ()

@property(nonatomic,strong) UIImageView *containerView;
@property(nonatomic,strong) UIButton *settingBluetoothButton;

@end

@implementation BluetoothConnectViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(popMainViewController) name:@"linnerConnect" object:nil];

}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)popMainViewController
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)didClickSettingBluetoothButton
{
    #define iOS10 ([[UIDevice currentDevice].systemVersion doubleValue] >= 10.0)
    NSString * urlString = @"App-Prefs:root=Bluetooth";
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:urlString]]) {
        if (iOS10) {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{} completionHandler:nil];
        } else {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
        }
    }
}

- (UIImageView *)containerView
{
    if(!_containerView)
    {
        UIView *superView = self.view;
        _containerView = [[UIImageView alloc]init];
        [superView addSubview:_containerView];
        _containerView.image = [UIImage imageNamed:MyNSLocalizedString(@"bluetooth_connect_zh")];
    }
    return _containerView;
}
- (UIButton *)settingBluetoothButton
{
    if(!_settingBluetoothButton)
    {
        UIView *superView = self.view;
        _settingBluetoothButton = [[UIButton alloc]init];
        [superView addSubview:_settingBluetoothButton];
        _settingBluetoothButton.layer.cornerRadius = 5;
        [_settingBluetoothButton setBackgroundColor:[UIColor colorWithRed:28/255.0 green:167/255.0 blue:134/255.0 alpha:1]];
        [_settingBluetoothButton setTitle:MyNSLocalizedString(@"进入手机蓝牙设置") forState:UIControlStateNormal];
//        [_settingBluetoothButton setTitleColor:<#(nullable UIColor *)#> forState:UIControlStateNormal];
        [_settingBluetoothButton.titleLabel setFont:[UIFont systemFontOfSize:15]];
        [_settingBluetoothButton addTarget:self action:@selector(didClickSettingBluetoothButton) forControlEvents:UIControlEventTouchUpInside];
    }
    return _settingBluetoothButton;
}


- (void)setNavigationStyle
{
    [self setNavigationBarTitle:MyNSLocalizedString(@"蓝牙连接")];
    [self setLeftButtonImage:[UIImage imageNamed:@"tittle_back_nor"]];
    [self.view bringSubviewToFront:self.navigationBar];
}

- (void)masLayoutSubview
{
    __weak UIView *superView = self.view;
    
    [self.containerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(superView.mas_top).with.offset(66);
        make.left.right.mas_equalTo(superView);
        make.height.mas_equalTo(px1920Height(1430));
    }];
    
    [self.settingBluetoothButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(superView.mas_centerX);
        make.top.mas_equalTo(self.containerView.mas_bottom);
        make.height.mas_equalTo(px1920Height(140));
        make.width.mas_equalTo(px1080Width(550));
    }];
}

@end
